package leetcode;

/**
 * @Author: Liu Yue
 * @Descripition: 相同的树
 * 给定两个二叉树，编写一个函数来检验它们是否相同。
 *
 * 如果两个树在结构上相同，并且节点具有相同的值，则认为它们是相同的。
 *
 * 示例 1:
 *
 * 输入:       1         1
 *           / \       / \
 *          2   3     2   3
 *
 *         [1,2,3],   [1,2,3]
 *
 * 输出: true
 * 示例 2:
 *
 * 输入:      1          1
 *           /           \
 *          2             2
 *
 *         [1,2],     [1,null,2]
 *
 * 输出: false
 * @Date; Create in 2020/2/21 16:27
 **/
public class Sametree {

    public boolean isSymmetric(TreeNode root) {
        return ismirror(root,root);
    }
    static boolean ismirror(TreeNode p, TreeNode q) {
        if(p == null && q == null){
            return true;
        }
        if(p == null || q == null){
            return false;
        }
        if(p.val != q.val){
            return false;
        }
        return ismirror(p.left,q.left) && ismirror(p.right,q.right);
    }
    public boolean ismirror2(TreeNode p, TreeNode q) {
        boolean left_correct = p == null && q == null || p != null && q != null && p.val == q.val && ismirror2(p.left, q.left);
        boolean right_correct = p == null && q == null || p != null && q != null && p.val == q.val && ismirror2(p.right, q.right);
        return left_correct && right_correct;
    }
    public boolean isSameTree2(TreeNode P){

        return false;
    }
    public static void main(String[] args) {

    }



}
class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode(int x) { val = x; }
 }

